﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Comet.ViewModel;

namespace Comet.View.Wpf
{
    /// <summary>
    /// Interaction logic for ConstructorFromDataMembersView.xaml
    /// </summary>
    public partial class DataMembersView : UserControl
    {
        /// <summary>   
        ///     Gets or sets the parent form. 
        /// </summary>
        /// <value> 
        ///     The parent form. 
        /// </value>
        public System.Windows.Forms.Form ParentForm
        {
            get;
            set;
        }

        /// <summary>   
        ///     Creates a new instance of the DataMembersView class. 
        /// </summary>
        /// <remarks>   
        ///     Simon, 23.02.2011. 
        /// </remarks>
        public DataMembersView()
        {
            InitializeComponent();
            IsVisibleChanged += new DependencyPropertyChangedEventHandler(DataMembersView_IsVisibleChanged);
        }

        /// <summary>   
        ///     Event handler. Called by DataMembersView for visibility change events. This event
        ///     is handled in order to load the data after the dialog is displayed. 
        ///     This is done because a problem with ListView, which won't auto-size its columns
        ///     if data is added before displaying the control.
        /// </summary>
        /// <remarks>   
        ///     Simon, 23.02.2011. 
        /// </remarks>
        /// <param name="sender">   Source of the event. </param>
        /// <param name="e">        Dependency property changed event information. </param>
        void DataMembersView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue == true)
            {
                DataMembersViewModel dataMembersViewModel = (DataMembersViewModel)DataContext;
                dataMembersViewModel.InitialiazeDataMembers();
            }
        }

        /// <summary>   
        ///     Event handler. Called by cancelButton for click events. 
        ///     Closes the dialog and discards changes.
        /// </summary>
        /// <remarks>   
        ///     Simon, 23.02.2011. 
        /// </remarks>
        /// <param name="sender">   Source of the event. </param>
        /// <param name="e">        Routed event information. </param>
        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.Form dialog = ParentForm;
            DataMembersViewModel viewModel = (DataMembersViewModel)DataContext;
            viewModel.ChangesAccepted = true;
            dialog.Close();
        }

        /// <summary>   
        ///     Event handler. Called by okButton for click events. 
        ///     Closes the dialog and accepts changes.
        /// </summary>
        /// <remarks>   
        ///     Simon, 23.02.2011. 
        /// </remarks>
        /// <param name="sender">   Source of the event. </param>
        /// <param name="e">        Routed event information. </param>
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.Form dialog = ParentForm;
            DataMembersViewModel viewModel = (DataMembersViewModel)DataContext;
            viewModel.ChangesAccepted = true;
            dialog.Close();
        }
    }
}
